﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace OrderModule.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class Init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WbOrder",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    OrderNo = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "订单号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Status = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, comment: "订单状态")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Amount = table.Column<decimal>(type: "decimal(9,2)", precision: 9, scale: 2, nullable: false, comment: "订单金额"),
                    RowVersion = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WbOrder", x => x.Id);
                },
                comment: "订单")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WbOrderItem",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    GoodsId = table.Column<int>(type: "int", nullable: false, comment: "商品Id"),
                    GoodsTitle = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "商品名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Quantity = table.Column<int>(type: "int", nullable: false, comment: "数量"),
                    OrderId = table.Column<int>(type: "int", nullable: true),
                    RowVersion = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WbOrderItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WbOrderItem_WbOrder_OrderId",
                        column: x => x.OrderId,
                        principalTable: "WbOrder",
                        principalColumn: "Id");
                },
                comment: "订单项")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_WbOrder_IsDeleted",
                table: "WbOrder",
                column: "IsDeleted");

            migrationBuilder.CreateIndex(
                name: "IX_WbOrderItem_IsDeleted",
                table: "WbOrderItem",
                column: "IsDeleted");

            migrationBuilder.CreateIndex(
                name: "IX_WbOrderItem_OrderId",
                table: "WbOrderItem",
                column: "OrderId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "WbOrderItem");

            migrationBuilder.DropTable(
                name: "WbOrder");
        }
    }
}
